package com.yunxin.customui.mapper;

import com.yunxin.customui.bean.PageConfig;
import com.yunxin.customui.bean.PageTemplate;
import com.yunxin.customui.bean.card.CardConfig;
import com.yunxin.customui.bean.echart.ChartCfgBean;
import com.yunxin.customui.bean.echart.ChartSqlConfig;
import com.yunxin.customui.bean.echart.ChartValCfgBean;
import com.yunxin.customui.bean.table.datatable.TableBusinessConfig;
import com.yunxin.customui.bean.table.datatable.TableDataTemplate;
import com.yunxin.customui.bean.table.sqltable.TableSqlColumn;
import com.yunxin.customui.bean.table.sqltable.TableSqlConfig;
import com.yunxin.customui.bean.menu.MenuBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 配置映射器
 * 业务层在 service包 dbservice包下
 *
 * @author lee
 * @date 2021/10/01
 */
@Mapper
public interface ConfigMapper {

    /**
     * 查询通过id卡配置
     *
     * @param cardId 卡id
     * @return {@link CardConfig}
     */
    @Select("select * from v_cardconfig card,v_component com where card.cardid = com.componentid and cardid = ${cardId}")
    CardConfig queryCardConfigById(Integer cardId);

    /**
     * 查询图配置id
     *
     * @param chartId 表id
     * @return {@link ChartCfgBean}
     */
    @Select("select * from v_chartconfig chart,v_component com where chart.chartid = com.componentid and chartid = ${chartId}")
    @Results({
            @Result(property = "chartID",column = "chartid"),
            @Result(property = "chartValCfgBeans", column = "chartID" ,
                    many = @Many(select = "com.yunxin.hdsystem.mapper.ConfigMapper.queryChartValCfgById"))
    })
    ChartSqlConfig queryChartConfigById(Integer chartId);

    @Select("select * from v_charttemplate where chartid = ${chartId}")
    List<ChartValCfgBean> queryChartValCfgById(Integer chartId);

    /**
     * 查询表sql列id
     *
     * @param tableId 表id
     * @return {@link List<TableSqlColumn>}
     */
    @Select("select * from v_table_sql_column where tableId = #{tableId} order by sort")
    List<TableSqlColumn> queryTableSqlColumnById(Integer tableId);

    /**
     * 表的sql查询配置id
     *
     * @param tableId 表id
     * @return {@link TableSqlConfig}
     */
    @Select("select * from v_table_sql_config table1,v_component com,v_tableconfig table2 where table1.tableid = com.componentid and table1.tableId = table2.tableid and table1.tableid = #{tableId}")
    TableSqlConfig queryTableSqlConfigById(Integer tableId);

    /**
     * 查询表业务模板id
     *
     * @param tableId 表id
     * @return {@link List<TableDataTemplate>}
     */
    @Select("select * from v_table_business_template  where  tableid = ${tableId}")
    List<TableDataTemplate>  queryTableBusinessTemplateById(Integer tableId);

    /**
     * 查询表业务配置id
     *
     * @param tableId 表id
     * @return {@link TableBusinessConfig}
     */
    @Select("select * from v_table_business_config table1,v_component com,v_tableconfig table2 where table1.tableid = com.componentid and table1.tableid = table2.tableid and table1.tableid = ${tableId}")
    TableBusinessConfig queryTableBusinessConfigById(Integer tableId);

    /**
     * 查询页面配置id
     *
     * @param pageId 页面id
     * @return {@link PageConfig}
     */
    @Select("select * from v_pageconfig where pageId = #{pageId}")
    @Results({

            @Result(property = "pageTemplates", column = "pageId" ,
                    many = @Many(select = "com.yunxin.hdsystem.mapper.ConfigMapper.queryPageTemplatesById"))
    })
    PageConfig queryPageConfigById(Integer pageId);

    /**
     * 查询页面模板id
     *
     * @param pageId 页面id
     * @return {@link List<PageTemplate>}
     */
    @Select("select * from v_pagetemplate where pageId = #{pageId}")
    List<PageTemplate> queryPageTemplatesById(Integer pageId);

    @Select("select * from v_treemenu where indexId = #{indexId}" )
    List<MenuBean> queryMenuById(Integer pageId);
}
